package org.dlsu.mt;

import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;

import org.dlsu.mt.parser.FStructure;
import org.dlsu.mt.parser.FStructureElement;
import org.dlsu.mt.parser.FStructureElementString;
import org.dlsu.mt.parser.Word;

/**
 * Implements a simple dictionary for expressions
 */

public class SimpleDictionary implements DictionaryInterface
{

	Hashtable dictionary = new Hashtable();

	/**
	 * Initializes the dictionary with entries
	 */
	public SimpleDictionary()
	{
		addEntry("id", "id");
		addEntry("+", "+");
		addEntry("*", "*");
		addEntry("(", "(");
		addEntry(")", ")");
		
		/**
		 * Filipino
		 */
		 
		/*
		addEntry("id", "proper_noun");
		addEntry("id", "pronoun");
		addEntry("John", "noun");
		addEntry("Mary", "noun");
		addEntry("si", "adj");
		addEntry("si", "conj");
		addEntry("si", "prep");
		addEntry("Hinalikan", "verb");
		addEntry("si", "aux");
		addEntry("si", "adv");
		addEntry("si", "nom");
		addEntry("si", "gen");
		addEntry("si", "dat");
		
		//addEntry("ni", "adj");
		//addEntry("ni", "conj");
		//addEntry("ni", "prep");
		//addEntry("ni", "aux");
		//addEntry("ni", "adv");
		addEntry("ni", "nom");
		//addEntry("ni", "gen");
		//addEntry("ni", "dat");
		*/
		
		/**
		 * English
		 */
		 
		///*
		addEntry("John", "noun");
		addEntry("John", "proper_noun");
		addEntry("John", "verb");
		addEntry("kissed", "verb");
		addEntry("Mary", "noun");
		addEntry("id", "proper_noun");
		//addEntry("the", "det");
		addEntry("id", "pronoun");
		addEntry("maitim", "adj");
		addEntry("and", "conj");
		//addEntry("ass", "prep");
		//addEntry("humped", "verb");
		addEntry("id", "aux");
		addEntry("id", "adverb");
		//addEntry("lim", "noun");
		
		addEntry("the", "det");
		addEntry("quick", "adj");
		addEntry("brown", "adj");
		addEntry("fox", "noun");
		addEntry("jumps", "verb");
		addEntry("over", "prep");
		addEntry("Marlon", "noun");
		addEntry("is", "verb");
		addEntry("lazy", "adj");
		addEntry("dog", "noun");
		addEntry("a", "aux");
		addEntry("pig", "noun");
		addEntry(",", "conj");
		//*/
	}

	/**
	 * Adds a tag to a word or token
	 *
	 * @param word The word or token to add attach a tag
	 * @param tag The tag to associate with the given word
	 */
	private void addEntry(String word,String tag)
	{
		Vector entries;

		if ( !dictionary.containsKey(word))
		{
			entries = new Vector();
			entries.addElement(tag);
			dictionary.put(word, entries);
		}
		else
		{
			entries = (Vector)dictionary.get(word);
			entries.addElement(tag);
		}
	}

	/**
	 * Looks up the dictionary given the word
	 *
	 * @param word The word or token to look up
	 * @return The word that has been lookedup with the associated tags and semantics, null if not found
	 */
	public Word lookup(Word word)
	{
		return lookup(word.getRootWord());
	}

	/**
	 * Looks up the dictionary given the word
	 *
	 * @param word The word or token to look up
	 * @return The word that has been lookedup with the associated tags and semantics, null if not found
	 */
	public Word lookup(String inputWord)
	{
/*		String origWord="";
		try {
			origWord = inputWord;
			Integer.parseInt(inputWord);
			inputWord = "id";
		} catch (Exception e) {}
		Word word = new Word(inputWord);
		HashSet hs = new HashSet();
		hs.add(new FStructureElementString(origWord));
		FStructure f = new FStructure(word.getRootWord());
		f.addEntry(new FStructureElement("value",hs));
		Vector posTags=null;
		try{
			posTags = (Vector) dictionary.get(inputWord);
		}
		catch(Exception e){};

		if (posTags != null)
		{
			for (int i =0; i< posTags.size(); i++) {
				word.addPOSTagEntry((String)posTags.elementAt(i), f);
			}

			return word;

		}*/
		
		/*
		Word word = new Word(inputWord);
		HashSet hs = new HashSet();
		hs.add(new FStructureElementString("X"));
		FStructure f = new FStructure("X");
		f.addEntry(new FStructureElement("X",hs));
		word.addPOSTagEntry(inputWord, f);
		return word;
		*/

//System.out.println("LOOKUP --------------------->");
		
		Word word = new Word(inputWord);
		HashSet hs = new HashSet();
		hs.add(new FStructureElementString(inputWord));
		FStructure f = new FStructure(word.getRootWord());
		f.addEntry(new FStructureElement(word.getCurrentPOSTag(),hs));
		//word.addPOSTagEntry(inputWord, f);
		//return word;
		
		Vector posTags=null;
		try{
			posTags = (Vector) dictionary.get(inputWord);
			//System.out.println("posTags : " + posTags);
		}
		catch(Exception e){};

		if (posTags != null)
		{
			for (int i =0; i< posTags.size(); i++) {
				word.addPOSTagEntry((String)posTags.elementAt(i), f);
			}
			return word;
		}
		
		return null;
	}
}